package com.wxr.utils;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

public class SendEmailUtil {

    //简单邮件发送
    public static  void sendSimpleMail(JavaMailSenderImpl javaMailSender, String subject,String content,String fromEamil,String toEmail){
        //简单的邮件测试
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setSubject("小王，早上好");
        simpleMailMessage.setText("感谢哦！");
        simpleMailMessage.setFrom("1301379511@qq.com");
        simpleMailMessage.setTo("1301379511@qq.com");
        javaMailSender.send(simpleMailMessage);
    }


    public static void sendMimeMail(JavaMailSenderImpl javaMailSender,Boolean html,String subject, String content, String attachmenName,String path, String fromEamil, String toEmail) throws MessagingException {
        //复杂的邮件测试
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        //组装
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,html);

        helper.setSubject("小王，晚上好！");
        helper.setText("<p style='color:red'>小王小王努力学习！</p>",html);
        //附件
        helper.addAttachment("1.jpg",new File("C:\\Users\\Administrator\\Pictures\\Camera Roll\\1.jpg"));
        //来源 发送给谁
        helper.setFrom("1301379511@qq.com");
        helper.setTo("1301379511@qq.com");
        javaMailSender.send(mimeMessage);

    }


}
